#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int t, n;
string a, b;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cin >> t;
    while (t--) {
        cin >> n;
        cin >> a >> b;
        if (a == b) {
            cout << 0 << endl;
            continue;
        }
        int an = 0, bn = 0;
        for (auto ch : a) {
            if (ch == '1') an++;
        }

        for (auto ch : b) {
            if (ch == '1') bn++;
        }
        int ans = 1e9;

        if (an == bn) {
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] != b[i]) cnt++;
            }
            ans = min(ans, cnt);
        }
        if (an + bn == n+1) {
            int cnt = 1, w = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] == '1' && b[i] == '1') w = i;
            }

            for (int i = 0; i < n; i++) {
                if (w == i) continue;
                a[i] = a[i] == '1' ? '0' : '1';
            }
            for (int i = 0; i < n ; i++) {
                if (a[i] != b[i]) cnt++;
            }

            ans = min(ans, cnt);
        }
        if (ans == 1e9 ) ans = -1;
        cout << ans << endl;
    }
    return 0;
}